﻿package 
{

	import flash.display.MovieClip;
	import flash.geom.Point;
		import flash.events.Event;

	public class Main extends MovieClip
	{


		public function Main()
		{
			trace("Main");
			
			init();
		}

		

		const cp:Point = new Point(150,200);
		const cp2:Point = new Point(400,200);
		const r:Number = 150;
		const r2:Number = 100;

		var radian:Number = 0;

		var crtRadius:Number = r;
		var crtPoint:Point = cp;
		var perRadian:Number = Math.PI / 27;
		var isLeft:Boolean = true;

		

		function init():void
		{
			this.addEventListener(Event.ENTER_FRAME, update);
		}

		function update(event:Event):void
		{
			radian +=  perRadian;

			ball.x = crtPoint.x + Math.cos(radian) * crtRadius;
			ball.y = crtPoint.y + Math.sin(radian) * crtRadius;

			if ( Point.distance( new Point(ball.x, ball.y), 
			   new Point(300,200) ) < 2)
			{
				//crtRadius = isLeft ? r2 : r;
				if (isLeft)
				{
					crtRadius = r2;
				}
				else
				{
					crtRadius = r;
				}
				trace("I am here!");

				//crtPoint = isLeft ? cp2: cp;
				if (isLeft)
				{
					crtPoint = cp2;
				}
				else
				{
					crtPoint = cp;
				}
				//radian += isLeft ? Math.PI : -Math.PI;
				if (isLeft)
				{
					radian +=  Math.PI;
				}
				else
				{
					radian +=   -  Math.PI;
				}
				perRadian *=  -1;
				isLeft = ! isLeft;
			}
		}
	}

}